const { ccclass, property } = cc._decorator;
import WinFormBase from '../WinFormBase';
import DetailsManager from './DetailsManager';
import hitMsgControl from '../Lobby/hitMsgControl';
import LevelTaskControl from './LevelTaskControl';
import skillsShow from './skillsShow';

@ccclass
export default class SelectModel extends cc.Component {
    @property(cc.Node)
    choiceNode: cc.Node = null;
    @property(cc.Node)
    skillNode: cc.Node = null;
    @property(cc.Label)
    level: cc.Label = null;
    @property(cc.Node)
    Details: cc.Node = null;
    @property(cc.Node)
    msgForm: cc.Node = null;
    @property(cc.Node)
    showTask: cc.Node = null;
    @property(cc.Node)
    skillList: cc.Node = null;
    _DetailsManager: DetailsManager = null;
    _LevelTaskControl: LevelTaskControl = null;
    _skillsShow: skillsShow = null;
    start() {
        this._DetailsManager = this.Details.getComponent(DetailsManager);
        this._LevelTaskControl = this.showTask.getComponent(LevelTaskControl);
        this._skillsShow = this.skillList.getComponent(skillsShow);
        this.updateLevel();
    }
    //关卡选择
    levelChoice() {
        let fromNode = new cc.Node();
        let fromControl = fromNode.addComponent(WinFormBase);
        var pageViewEventHandler = new cc.Component.EventHandler();
        pageViewEventHandler.target = this.node;
        pageViewEventHandler.component = "SelectModel"
        pageViewEventHandler.handler = "updateLevel";
        fromControl.CloseEvents.push(pageViewEventHandler);
        fromControl.isBgClose = true;
        fromControl.mainNode = this.choiceNode;
        this.node.addChild(fromNode);
    }
    updateLevel() {
        let LevelId = gameHelper.getInstance().selectLevelId;
        this.level.string = LevelId.toString();
        this._LevelTaskControl.showStr();
        this.updateSkill();
    }
    //出场技能选择
    skillChoice() {
        let fromNode = new cc.Node();
        let fromControl = fromNode.addComponent(WinFormBase);
        var pageViewEventHandler = new cc.Component.EventHandler();
        pageViewEventHandler.target = this.node;
        pageViewEventHandler.component = "SelectModel"
        pageViewEventHandler.handler = "updateSkill";
        fromControl.CloseEvents.push(pageViewEventHandler);
        fromControl.isBgClose = true;
        fromControl.mainNode = this.skillNode;
        this.node.addChild(fromNode);
    }
    updateSkill() {
        let LevelP = gameHelper.getInstance().getLevelParam();
        this._skillsShow.show(LevelP.SkillHit, LevelP.SkillPut, LevelP.SkillSelf);
    }

    //难度切换
    gradeChoice(grade: string) {

    }
    //闯关
    cg() {
        if (!this._DetailsManager)
            this._DetailsManager = this.Details.getComponent(DetailsManager);
        if (this._DetailsManager.disburseFtg(10) >= 0) {
            HeroManager.getInstance().ReSetGame();
            cc.director.loadScene("GameLoadin");
        }
        else {
            this.showMsg("体力已经透支了，休息一下吧");
        }
    }
    //冒险
    mx() {
    }

    showMsg(msg: string) {
        let control = this.msgForm.getComponent(hitMsgControl)
        control.lebelNode.string = msg;
        let formNode = new cc.Node();
        let formControl = formNode.addComponent(WinFormBase);
        formControl.formIndex = 2
        formControl.mainNode = this.msgForm;
        this.node.addChild(formNode);
    }
}
